<?php
  require_once('./db.php');
 // echo '<pre>';
  //print_r($_POST);

  if(isset($_POST['email']) && !empty($_POST['email']) &&
  isset($_POST['password']) && !empty($_POST['password'])) {

    $email = $_POST['email'];
    $password = md5($_POST['password']);
    $where = "`email`='$email' AND (`password`='$password'  ) AND status='1'";
    $result = fetchAll('users',$where);
    if(mysql_num_rows($result) == 1) {
      $user = mysql_fetch_assoc($result);
      $_SESSION['id'] = $user['id'];
      $_SESSION['name'] = $user['name'];
      $_SESSION['email'] = $user['email'];
      //print_r($user);
      header("location:index.php");
      exit;
    } else {
      $msg = "Invalid username / password.";
    }
  }
 //  echo '</pre>';
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="./assets/ico/favicon.ico">

    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="./dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="./css/signin.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy this line! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <div class="container">
<?php
if($msg !='') {
?>
<div class="alert alert-dismissable alert-warning">
              <button data-dismiss="alert" class="close" type="button">×</button>
              <h4><?=$msg?></h4>
            </div>
<?php
}
?>

      <form class="form-signin" role="form" method="post">
        <h2 class="form-signin-heading">Please sign in</h2>
        <input type="text" name="email" class="form-control" placeholder="Email address"  autofocus>
        <input type="password" name="password" class="form-control" placeholder="Password" >
        <label class="checkbox">
          <input type="checkbox" value="remember-me"> Remember me
        </label>
        <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
      </form>

    </div> <!-- /container -->

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<?php
if($isDebug) {
?>
  <hr>
  <h4>Debug:-</h4>
  <?php
  foreach ($logArr as $msg)
  {
    echo $msg;
  }

  ?>
  <hr>
<?php
}//end if
?>
</div>
    <!-- Bootstrap core JavaScript
    ================================================== -->
        <script src="./dist/js/bootstrap.min.js"></script>
    <script src="./assets/js/docs.min.js"></script>
    <!-- Placed at the end of the document so the pages load faster -->
  </body>
</html>
